# 注意：这只是一个临时文件（应该吧）

from rocketpart import *

if __name__ == '__main__':
    db.connect()
    db.create_tables([KindOfEngineCycle, KindOfFuel, KindOfTank, 
                    Engine, RocketStage, Tank, Rocket, 
                    StageAndRocket, EngineGroup, EngineTeam])
    while True:
        print('选择设置 1:新建燃料罐种类 2:新建燃料种类 3:新建发动机种类')
        print('4:新建发动机 5:新建火箭分级 6:新建燃料罐')
        print('7:新建完整火箭 8:测试火箭计算dv功能')
        choice = input('请输入:')
        print(choice)

        if choice == '1':
            stupid = [None, None, None]
            stupid[0] = float(input('请输入空质量/容积比:'))
            stupid[1] = float(input('请输入价格/容积比:'))
            stupid[2] = input('请输入名字:')
            print('ok')
            KindOfTank.create(name=stupid[2], mass_each_volume=stupid[0], price_each_volume=stupid[1])
        elif choice == '2':
            stupid = [None, None, None, None]
            stupid[0] = input('请输入名字:')
            stupid[1] = float(input('请输入密度(kg/L):'))
            stupid[2] = float(input("请输入价格(D/L):"))
            stupid[3] = float(input("请输入基准比冲(s):"))
            print('ok')
            KindOfFuel.create(name=stupid[0], density=stupid[1], 
                            price_each_volume=stupid[2], base_lsp=stupid[3])
        elif choice == '3':
            stupid = [None, None, None, None, None, None, None, None]
            stupid[0] = input("请输入名字:")
            stupid[1] = float(input("请输入比冲修正上限:"))
            stupid[2] = float(input("请输入比冲修正下限:"))
            stupid[3] = float(input("请输入价格修正上限:"))
            stupid[4] = float(input("请输入价格修正下限:"))
            stupid[5] = float(input("请输入生产所需基准时间:"))
            stupid[6] = float(input("请输入质量修正量:"))
            KindOfEngineCycle.create(name=stupid[0], lsp_factor_max=stupid[1], lsp_factor_min=stupid[2],
                                    price_factor_max=stupid[3], price_factor_min=stupid[4],
                                    develop_time=stupid[5], mass_factor=stupid[6], develop_skill=0, test=1)
            print('ok')
        elif choice == '4':
            stupid = [None, None, None, None, None, None, None]
            stupid[0] = input("请输入名字:")
            stupid[1] = float(input("请输入技术比重:"))
            stupid[2] = float(input("请输入成本比重:"))
            stupid[3] = float(input("请输入生产时间比重:"))
            stupid[4] = float(input("请输入推力:"))
            cycles = KindOfEngineCycle.select()
            print("循环方式:")
            for cycle in cycles:
                print(cycle.name)
            stupid[5] = int(input("请选择:"))
            fuels = KindOfFuel.select()
            print("燃料种类:")
            for fuel in fuels:
                print(fuel.name)
            stupid[6] = int(input("请选择:"))

            new_engine = Engine()
            new_engine.post_init(name=stupid[0], force=stupid[4],
                                tech_price={'tech':stupid[1], 'price':stupid[2], 'time':stupid[3]},
                                kofuel=stupid[6]+1, kocycle=stupid[5]+1)
            new_engine.save()
            print("lsp:" + str(new_engine.lsp))
            print('base_price:' + str(new_engine.base_price))
            print('ok')
        elif choice == '6':
            stupid = [None] * 4
            stupid[0] = input("请输入名字")
            tanks = KindOfTank.select()
            print("储箱种类:")
            for tank in tanks:
                print(tank.name)
            stupid[1] = int(input("请选择:"))
            fuels = KindOfFuel.select()
            print("燃料种类:")
            for fuel in fuels:
                print(fuel.name)
            stupid[2] = int(input("请选择:"))
            stupid[3] = float(input("请输入容量(tons)"))
            
            new_tank = Tank()
            new_tank.post_init(name=stupid[0], kofuel=stupid[2]+1, kotank=stupid[1]+1, tons=stupid[3])
            new_tank.save()
            print("total_price"+str(new_tank.empty_price + new_tank.fuel_price))
            print('ok')
        elif choice == '5':
            stupid = [None] * 10
            stupid[0] = input("请输入名字:")

            tanks = Tank.select()
            print("可用储箱:")
            for tank in tanks:
                print(tank.name)
            stupid[1] = int(input("请选择:"))

            engines = Engine.select()
            engine_list = {}
            new_engine_group = EngineGroup()
            print("可用发动机:")
            for engine in engines:
                print(engine.name)
                engine_list[engine.id] = int(input("请输入这款发动机的安装数量:"))
                if engine_list[engine.id] >= 1:
                    new_engine_team = EngineTeam(engine=engine, amount=engine_list[engine.id], 
                            owner=new_engine_group)

            new_engine_group.save()
            new_rocket_stage = RocketStage()
            new_rocket_stage.post_init(name=stupid[0], engine_group=new_engine_group, tank=stupid[1]+1)
            new_rocket_stage.save()
            print(new_rocket_stage.total_price)
            print('ok')
        elif choice == '7':
            stupid = [None] * 10
            stages = [None] * 100
            stupid[0] = input("请输入名字:")
            print("显示火箭分级:")
            rocket_stage = RocketStage.select()
            series = 1
            while True:
                print("选择第"+str(series)+'级')
                for stage in rocket_stage:
                    print(stage.name+' '+str(stage.total_price)+' '+str(stage.total_mass))
                stages[series] = input("请输入你的选择:")
                if stages[series] == 'exit':
                    break
                else:
                    stages[series] = int(stages[series])
                series += 1

            new_rocket = Rocket(name=stupid[0])
            new_rocket.save()
            series = 1
            while True:
                if stages[series] == (None or 'exit'):
                    break
                StageAndRocket.create(stage=RocketStage.select().where(RocketStage.id == int(stages[series])+1), 
                    rocket=new_rocket, series=series)
                series += 1
            new_rocket.count_everything()
            new_rocket.save()
            print('ok')
        elif choice == '8':
            rockets = Rocket.select()
            print("展示火箭")
            for rocket in rockets:
                print(rocket.name)
            stupid = [None] * 10
            stupid[0] = int(input("请选择:"))
            stupid[1] = float(input("请输入载荷质量:"))
            stupid[2] = Rocket.get(Rocket.id == stupid[0]+1)
            stupid[3] = stupid[2].check_dv(stupid[1])
            if stupid[3]['result'] == 1:
                print("推重比过小，无法起飞")
            else:
                print('这款火箭搭载指定载荷的DV值为:')
                print(stupid[3]['reason'])
            print('ok')
        else:
            break

    db.close()